<template>
	<jk-dialog
		v-model="showDialog"
		title="详情-物料"
		width="800px"
		:show-content-loading="showLoading"
		append-to-body
		@on-cancel="onVisibleChange(false)"
		@on-visible-change="onVisibleChange"
	>
		<el-form ref="ruleForm" :model="ruleForm" label-width="120px" :show-message="false">
			<el-row>
				<el-col :span="24">
					<el-form-item class="margin-bottom-10" label="物料分类" prop="categoryId">
						<span class="read-only-2">{{ ruleForm.categoryName }}</span>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item class="margin-bottom-10" label="编码" prop="code">
						<span class="read-only-2">{{ ruleForm.code }}</span>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item class="margin-bottom-10" label="名称" prop="name">
						<span class="read-only-2">{{ ruleForm.name }}</span>
					</el-form-item>
				</el-col>
				<!--<el-col :span="12">
					<el-form-item class="margin-bottom-10" label="规格型号" prop="models">
						<span class="read-only-2">{{ ruleForm.models }}</span>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item class="margin-bottom-10" label="条码">
						<span class="read-only-2">{{ ruleForm.barCode }}</span>
					</el-form-item>
				</el-col>-->
				<el-col :span="12">
					<el-form-item class="margin-bottom-10" label="计量单位" prop="unitId">
						<span class="read-only-2">{{ ruleForm.unitName }}</span>
					</el-form-item>
				</el-col>
				<!--<el-col :span="12">
					<el-form-item class="margin-bottom-10" label="辅助计量单位">
						<span class="read-only-2">{{ ruleForm.secUnitName }}</span>
					</el-form-item>
				</el-col>-->
				<el-col :span="12">
					<el-form-item class="margin-bottom-10" label="存货类型">
						<div class="read-only-2">{{ ruleForm.typeName }}</div>
					</el-form-item>
				</el-col>
				<!--<el-col :span="12">
					<el-form-item class="margin-bottom-10" label="是否生产">
						<span class="read-only-2">{{ ruleForm.ifProduction ? '是' : '否' }}</span>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item class="margin-bottom-10" label="是否启用批号">
						<span class="read-only-2">{{ ruleForm.enableBatch ? '是' : '否' }}</span>
					</el-form-item>
				</el-col>-->
			</el-row>
			<jk-divider-card title="物料参数" placement="center" class="margin-top-10">
				<el-row>
					<el-col :span="12">
						<el-form-item class="margin-bottom-10" label="支数">
							<div class="read-only-2">{{ ruleForm.yarnCount }}</div>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item class="margin-bottom-10" label="定量(g/m)">
							<div class="flex-start">
								<div class="read-only-2">{{ ruleForm.gramWeight }}</div>
								<span style="margin: 0 5px;">/</span>
								<div class="read-only-2">{{ ruleForm.meters }}</div>
							</div>
						</el-form-item>
					</el-col>
					<!--<el-col :span="12">
						<el-form-item class="margin-bottom-10" label="默认生产区域">
							<div class="read-only-2">{{ ruleForm.workshopName }}</div>
						</el-form-item>
					</el-col>-->
					<el-col :span="12">
						<el-form-item class="margin-bottom-10" label="工序">
							<div class="read-only-2">{{ ruleForm.processName }}</div>
						</el-form-item>
					</el-col>
					<!--<el-col :span="12">
						<el-form-item class="margin-bottom-10" label="默认工艺路线">
							<div class="read-only-2">{{ ruleForm.specPathName }}</div>
						</el-form-item>
					</el-col>-->
					<el-col :span="12">
						<el-form-item class="margin-bottom-10" label="纺纱方式">
							<div class="read-only-2">{{ ruleForm.spinTypeName }}</div>
						</el-form-item>
					</el-col>
					<!--<el-col :span="12">
						<el-form-item class="margin-bottom-10" label="纺纱工艺">
							<div class="read-only-2">{{ ruleForm.technologyName }}</div>
						</el-form-item>
					</el-col>-->
					<el-col :span="12">
						<el-form-item class="margin-bottom-10" label="纱线用途">
							<div class="read-only-2">{{ ruleForm.purposeName }}</div>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item class="margin-bottom-10" label="原料成分">
							<div class="read-only-2">{{ ruleForm.componentName }}</div>
						</el-form-item>
					</el-col>
					<!--<el-col :span="24">
						<el-form-item class="margin-bottom-10" label="供应商">
							<div class="read-only-2">{{ ruleForm.supplier }}</div>
						</el-form-item>
					</el-col>-->
				</el-row>
			</jk-divider-card>
		</el-form>
	</jk-dialog>
</template>

<script>
    import calHeight from '/src/mixins/cal-table-height';
    import { spinProductGet } from '../../../api/material/material';

    export default {
        props: {
            dialogState: {
                type: Boolean,
                default: false
            },
            dataId: {
                type: [String, Number],
                default: ''
            }
        },
        mixins: [calHeight],
        data() {
            return {
                showDialog: false,
                showLoading: true,
                ruleForm: {}
            };
        },
        methods: {
            onVisibleChange(e) {
                this.$emit('on-visible-change', e);
                if (!e) {
                    Object.assign(this.$data, this.$options.data());
                }
            },
            getDetailRequest() {
                this.showLoading = true;
                return spinProductGet({ id: this.dataId }).then(res => {
                    this.showLoading = false;
                    if (res.data.status === 200) {
                        this.ruleForm = res.data.res;
                    }
                });
            }
        },
        watch: {
            dialogState(newVal) {
                this.showDialog = newVal;
                if (newVal && this.dataId) {
                    this.getDetailRequest();
                }
            }
        }
    };
</script>
